<template>
    <div class="feedback">
        <div class="header">
            <van-nav-bar title="建议与反馈" left-arrow @click-left="handleLeft" />
        </div>
        <div class="feedback_box">
            <van-form @submit="onSubmit" required>
                <div class="form_box">
                    <van-field v-model="queryParams.content" name="username" label="反馈内容" placeholder="请输入反馈内容"
                        :rules="[{ required: true, trigger: 'onChange', message: '请输入反馈内容' }]" />
                    <van-field v-model="queryParams.phone" name="password" label="联系电话" placeholder="请输入联系电话"
                        :rules="[{ required: true, trigger: 'onChange', message: '请输入联系电话' }, { validator: validatorPhone, trigger: 'onChange', message: '请输入正确电话' }]" />
                </div>
                <div class="form_btn">
                    <van-button round block type="primary" native-type="submit">
                        提交
                    </van-button>
                </div>
            </van-form>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ideasAndFeedback } from '@/api/operation/index'
import { showToast } from 'vant';

const router = useRouter()

const queryParams = ref({
    phone: '',
    content: ''
})

const validatorPhone = (val) => {
    if (val && val.length >= 11) {
        return /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(val);
    } else {
        return false
    }
}

const onSubmit = async () => {
    await ideasAndFeedback(queryParams.value)
    showToast('提交成功')
    handleLeft()
};

const handleLeft = () => {
    router.back()
}
</script>

<style lang="less" scoped>
.feedback {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-flow: column;

    .header {
        background: linear-gradient(#CDECFF 0%, #FFFFFF 70%);
        filter: blur(0px);
        height: 90px;
        padding-top: 44px;
        box-sizing: border-box;

        :deep(.van-icon-arrow-left) {
            color: #1a1b1c !important;
        }

        :deep(.van-nav-bar) {
            background: none !important;
        }

        :deep(.van-nav-bar__content) {
            background-color: transparent !important;
        }
    }

    .feedback_box {
        flex: 1;
        min-height: 0;

        :deep(.van-form) {
            width: 100%;
            height: 100%;
            display: flex;
            flex-flow: column;

            .form_box {
                flex: 1;
                min-height: 0;
                overflow-y: auto;
                margin: 10px;
                box-sizing: border-box;
                background: #fff;
            }

            .form_btn {
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                padding: 20px 15px;
                box-sizing: border-box;
                border-top: 1px solid #E2E4E8;
            }
        }
    }
}
</style>